/*
 * main.cpp
 *
 *  Created on: Jan 13, 2014
 *      Author: ppks
 */

#include "common.h"
#include "Serial.h"
#include "i2c.h"
#include "FlightController.h"

/******************************************************************************/
/* Global Variables Declaration                                               */
/******************************************************************************/

/******************************************************************************/
/* Local Function Prototypes                                                  */
/******************************************************************************/
static void SetupHardware(void);

/******************************************************************************/
/* Function Code                                                              */
/******************************************************************************/

/*******************************************************************************
* Function Name: SetupHardware()
********************************************************************************
* Summary:
*  Setups the hardware based on board type and other configuration made in
*  config.h file
*
* Parameters:
*  None
*
* Return:
*  None
*
*******************************************************************************/
static void SetupHardware(void)
{
    /* Initialize the com ports available in the chip */
    CommSerial_Open(0, SERIAL0_COM_SPEED);
#if defined(MEGA)
    CommSerial_Open(1, SERIAL1_COM_SPEED);
    CommSerial_Open(2, SERIAL2_COM_SPEED);
    CommSerial_Open(3, SERIAL3_COM_SPEED);
#endif

    /* Initialize LEDs */
    LEDPIN_SET_PINMODE;
    POWERPIN_SET_PINMODE;
    BUZZERPIN_SET_PINMODE;
    STABLEPIN_SET_PINMODE;
    POWERPIN_OFF;

    /* Turn on Power LED */
    POWERPIN_ON;

    /* Init I2C */
    CommI2C_Init();
}

/******************************************************************************/
/* Main Code                                                                  */
/******************************************************************************/
/*******************************************************************************
* Function Name: main()
********************************************************************************
* Summary:
*  main code to be executed at startup
*
* Parameters:
*  None
*
* Return:
*  None
*
*******************************************************************************/
int main(void)
{
	/* Initialize the chip hardware */
    init();

    /* Setup the board based on selected configuration in config.h file */
    SetupHardware();

    /* Launch FlightController Firmware */
    FlightController_Init();
    FlightController_Main();

    /* Infinite Loop */
    for(;;)
	{
	}

	return 0;
}





